package business;

import java.io.Serializable;
import java.util.ArrayList;
import databaseproject.*;

public class Cart implements Serializable
{
    private ArrayList<LineItem> items;
    
    public Cart()
    {
        items = new ArrayList<LineItem>();
    }
    
    public ArrayList<LineItem> getItems()
    { 
        return items;
    }
    
    public int getCount()
    { 
        return items.size();
    }
    
    public void addItem(LineItem item)
    {
        //int code = item.getProduct().getProduct_id();
        //int quantity = item.getQuantity();
        //for (int i = 0; i < items.size(); i++)
       // {
         //   LineItem lineItem = items.get(i);
         //   if (lineItem.getProduct().getProduct_id() == code)
          //  {
          //      lineItem.setQuantity(quantity);
         //       return;
          //  }
        //}
        items.add(item);
    }
    
    public void removeItem(LineItem item)
    {
        int code = item.getProduct().getProduct_id();
        for (int i = 0; i < items.size(); i++)
        {
            LineItem lineItem = items.get(i);
            if (lineItem.getProduct().getProduct_id() == code)
            {
                items.remove(i);
                return;
            }
        }
    }
    
    public static void main(String args[])
    { 
        Cart cart = new Cart();
        
        LineItem line = new LineItem();
        
        line.setProduct(new Products());
        line.getProduct().setProduct_id(1);
        line.getProduct().setName("widget");
        
        LineItem line2 = new LineItem();
        
        line.setProduct(new Products());
        line.getProduct().setProduct_id(2);
        line.getProduct().setName("test");
        
        LineItem line3 = new LineItem();
        
        line.setProduct(new Products());
        line.getProduct().setProduct_id(3);
        line.getProduct().setName("blue");
        
        cart.addItem(line);
        cart.addItem(line2);
        cart.addItem(line3);
        
        System.out.println(String.valueOf(cart.getCount()));
    }
}